// 通用API响应类型
export interface ApiResponse<T = any> {
  code: number
  data: T
  message: string
  success: boolean
}

// 分页请求参数
export interface PageParams {
  page: number
  pageSize: number
  keyword?: string
}

// 分页响应数据
export interface PageData<T> {
  list: T[]
  total: number
  page: number
  pageSize: number
  totalPages: number
}

// 用户相关类型
export interface User {
  id: number
  username: string
  email: string
  phone?: string
  avatar?: string
  role: string
  status: number
  createTime: string
  updateTime: string
}

export interface LoginParams {
  username: string
  password: string
  captcha?: string
}

export interface LoginResponse {
  token: string
  user: User
  expires: number
}

// TMS相关类型定义（运输管理系统）
export interface Vehicle {
  id: number
  plateNumber: string
  vehicleType: string
  capacity: number
  status: 'available' | 'busy' | 'maintenance'
  driverId?: number
  createTime: string
  updateTime: string
}

export interface Driver {
  id: number
  name: string
  phone: string
  licenseNumber: string
  licenseType: string
  status: 'active' | 'inactive'
  vehicleId?: number
  createTime: string
  updateTime: string
}

export interface Order {
  id: number
  order_number: string
  item_name: string
  quantity: number
  unit_length: number
  unit_width: number
  unit_height: number
  total_weight: number
  total_volume: number
  is_fragile: boolean
  temperature_control: string
  is_hazardous: boolean
  packaging_type: string
  notes: string
  createdAt: string
  createdBy: string
  lastModifiedAt: string
  lastModifiedBy: string | null
}

export interface Address {
  province: string
  city: string
  district: string
  detail: string
  contact: string
  phone: string
  longitude?: number
  latitude?: number
}

export interface Goods {
  id: number
  name: string
  category: string
  weight: number
  volume: number
  quantity: number
  value: number
  description?: string
}

export interface Route {
  id: number
  starting_point: string
  start_address: string
  destination: string
  destination_address: string
  is_out: boolean
  consignor_name: string
  phone: string
  consignor_unit: string
  description: string
  total_distance: string
  estimated_time: string
  createdAt: string
  createdBy: string
  lastModifiedAt: string
  lastModifiedBy: string | null
}

export interface Waypoint {
  id: number
  address: Address
  arrivalTime?: string
  departureTime?: string
  status: 'pending' | 'arrived' | 'departed'
  notes?: string
}

// 统计数据类型
export interface DashboardStats {
  totalOrders: number
  pendingOrders: number
  inTransitOrders: number
  completedOrders: number
  totalVehicles: number
  availableVehicles: number
  totalDrivers: number
  activeDrivers: number
  totalRevenue: number
  monthlyRevenue: number
}

// 订单列表API响应
export interface OrderListResponse {
  totalCount: number
  totalPage: number
  data: Order[]
}

// 搜索和筛选参数
export interface OrderSearchParams {
  PageIndex: number
  PageSize: number
  Order_number?: string
  Item_name?: string
}

export interface VehicleSearchParams extends PageParams {
  status?: string
  vehicleType?: string
}

export interface DriverSearchParams extends PageParams {
  status?: string
  licenseType?: string
}

// 发票相关类型定义
export interface Invoice {
  id: number
  invoiceNo: string
  distributorName: string
  invoiceType: string
  invoiceAmount: number
  taxRate: number
  taxAmount: number
  invoiceDate: string
  notes: string
  preparer: string
  createdTime: string
  purchaseSalesInvoices: boolean
  selected?: boolean
}

export interface InvoiceSearchParams {
  PageIndex: number
  PageSize: number
  DistributorName?: string
  InvoiceType?: string
  InvoiceDate?: string
}

export interface InvoiceListResponse {
  totalCount: number
  totalPage: number
  data: Invoice[]
}

// 合同追踪相关类型定义
export interface ContractTrackingListParams {
  PageIndex: number
  PageSize: number
  ContractNumber?: string
  ContractType?: string
  OwnerName?: string
  LicensePlateNumber?: string
  HasAbnormal?: boolean
}

export interface OrderInfo {
  id: number
  orderNumber: string
  itemName: string
  quantity: number
  totalWeight: number
  totalVolume: number
}

export interface VehicleLocation {
  vehicleId: number
  licensePlateNumber: string
  brandAndModel: string
  vehicleType: string
  ownerName: string
  vehicleStatus: string
  locationStatus: string
  currentLongitude: number
  currentLatitude: number
  currentLocationDesc: string
  lastUpdateTime: string
  transportStatus: string
}

export interface ContractTrackingItem {
  contractId: number
  contractNumber: string
  contractTitle: string
  contractType: string
  ownerName: string
  signingDate: string
  contractAmount: number
  orderInfo: OrderInfo
  vehicles: VehicleLocation[]
  currentStatus: string
  lastUpdateTime: string
  hasAbnormal: boolean
}

export interface ContractTrackingListResponse {
  items: ContractTrackingItem[]
  totalCount: number
  pageIndex: number
  pageSize: number
  totalPages: number
  hasPreviousPage: boolean
  hasNextPage: boolean
}

export interface RouteInfo {
  id: number
  startingPoint: string
  startAddress: string
  destination: string
  destinationAddress: string
  totalDistance: string
  estimatedTime: string
}

export interface TrackingLog {
  id: number
  contractId: number
  eventTime: string
  eventDescription: string
  locationLat: number
  locationLng: number
  locationDesc: string
  licensePlateNumber: string
  isAbnormal: boolean
}

export interface StationRecord {
  stationIndex: number
  stationName: string
  arrivalTime: string
  departureTime: string
  stayDuration: number
  locationLat: number
  locationLng: number
  status: string
  remarks: string
}

export interface ContractTrackingDetail {
  contractInfo: ContractTrackingItem
  routeInfo: RouteInfo
  trackingLogs: TrackingLog[]
  stationRecords: StationRecord[]
}

export interface AddTrackingLogParams {
  contractId: number
  eventTime: string
  eventDescription: string
  locationLat: number
  locationLng: number
  licensePlateNumber: string
  isAbnormal: boolean
}

export interface BatchAddTrackingLogParams {
  trackingLogs: AddTrackingLogParams[]
}